package com.yuyu.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URLDecoder;
import java.net.URLEncoder;

/**
 * 编码与解码操作工具类
 * author:yuyu
 * Date:2018/10/21
 * Time:23:50
 */
public final class CodecUtil {
    private static final Logger LOGGER = LoggerFactory.getLogger(CodecUtil.class);


    /**
     * 将url编码
     * @param source
     * @return
     */
    public static String encodeURL(String source) {
        String target = null;
        try {
            target = URLEncoder.encode(source, "UTF-8");
        } catch (Exception e) {
            LOGGER.error("url编码失败", e);
        }
        return target;
    }

    /**
     * 将url解码
     * @param source
     * @return
     */
    public static String doCodeURL(String source){
        String target = null;
        try {
            target = URLDecoder.decode(source, "UTF-8");
        } catch (Exception e) {
            LOGGER.error("url解码失败", e);
        }
        return target;
    }


}
